-- 跨服工会战失败

local IconRender = require("app.widget.renders.IconRender")
local GuildWarBattleLosePop = class("GuildWarBattleLosePop", app.mvc.ViewBase)
local CrossServerGuildWarHelper = require("app.crossServer.views.guildWar.CrossServerGuildWarHelper")

GuildWarBattleLosePop.VIEW_ROOT_RES = Res.CSGuildWarWinLosePop

function GuildWarBattleLosePop:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)
    self._ui.tips_1:setString(string.format(L("WGWMyCombat"), UD.csGuildWarData:getScore()))
    local rewards = CrossServerGuildWarHelper.getBattleLoseAward()
    for i = 1, 3 do
        local render = IconRender.createWithData( itemData, self._ui["icon_" .. i] )
        render:setData(rewards[i])
        render:setTipEnable( true )
        render:setTipUnShowOrigin( true )
    end
    self:_autoAdjustRewardPanel(#rewards)
end

-- 自动调整奖励panel中奖励posX
function GuildWarBattleLosePop:_autoAdjustRewardPanel(visibleNum)
    for i = 1, 3 do
        self._ui["icon_" .. i]:setVisible(i <= visibleNum)
    end

    if 1 == visibleNum then
        self._ui.icon_1:setPositionX(self._ui.icon_2:getPositionX())
    elseif 2 == visibleNum then
        local width = self._ui.Panel:getContentSize2()
        self._ui.icon_1:setPositionX( width*0.35 - 38) -- 常量系数是UI中的posX比例
        self._ui.icon_2:setPositionX( width*0.65 - 38)
    end
end

return GuildWarBattleLosePop
